export default {
  addCart(context, payload){
    return new Promise((resolve, reject) => {
      //1.查找之前数组中是否有该商品
      let oldProduct = context.state.cartList.find(item => item.iid === payload.iid)

      //2.判断oldProduct
      if (oldProduct){
        //商品数量+1
        context.commit('addCounter', oldProduct)
        resolve('商品数量+1')
      }else {
        //添加商品
        payload.count = 1
        context.commit('addToCart', payload)
        // context.state.cartList.push(payload)
        resolve('添加商品成功')
      }
    })


  }
}
